<?php
namespace app\common\library\util;

class AES
{
    protected static $method = 'aes-128-cbc';
    protected static $key = 'fthrfuhjtryu13t521y3it5i4t65hd1fh3gd2hg1er85r';
    protected static $iv = 'asdew12358dfgrty';

    /**
     * aes加密
     * @param $data
     * @return string
     * @throws \Exception
     * Author: LCY<409028735@qq.com>
     * Time: 2021/1/5 13:57
     * Note:
     */
    public static function encrypt($data)
    {
        $res = openssl_encrypt($data,self::$method,self::$key,OPENSSL_RAW_DATA,self::$iv);
        if(false === $res){
            return false;
        }

        return base64_encode($res);
    }

    /**
     * AES解密
     * @param $data
     * @return string
     * @throws \Exception
     * Author: LCY<409028735@qq.com>
     * Time: 2021/1/5 14:03
     * Note:
     */
    public static function decrypt($data)
    {
        $res = openssl_decrypt(base64_decode($data),self::$method,self::$key,OPENSSL_RAW_DATA,self::$iv);
        if(false === $res){
            return false;
        }

        return $res;
    }


}